package reflect;

import java.lang.reflect.Array;

public class JDK8JavaArrayMethodGetLength {
    public static void main(String[] args) {
//        referenceType();
        baseType();

    }

    /**
     * 基本数据类型
     */
    private static void baseType() {
        int[] test1 = {0,1};
        int[] test2 = {};
        System.out.println(Array.getLength(test1));
        System.out.println(Array.getLength(test2));
    }

    /**
     * 引用数据类型
     */
    private static void referenceType() {
        String[] test1 = {"1"};
        String[] test2 = {"1","2"};
        String[] test3 = {null,null};
        String[] test4 = {};

        System.out.println(Array.getLength(test1));
        System.out.println(Array.getLength(test2));
        System.out.println(Array.getLength(test3));
        System.out.println(Array.getLength(test4));

//        System.out.println(Array.getLength(null));
//        抛NPE
//        Exception in thread "main" java.lang.NullPointerException

//        String s = "1";
//        System.out.println(Array.getLength(s));
//        ↑会抛出参数异常
//        java.lang.IllegalArgumentException: Argument is not an array
    }
}
